// /src/qiankun/action.js
import { initGlobalState, MicroAppStateActions } from "qiankun";
function emptyAction(a: any, b?: boolean) {
  // 提示当前使用的是空 Action
  console.log(a, b);
  console.warn("Current execute action is empty!");
}
function emptyAction2(state: Record<string, any>) {
  console.log(state);
  console.warn("Current execute action is empty!");
}
class Actions {
  // 默认值为空 Action
  actions = {
    onGlobalStateChange: emptyAction,
    setGlobalState: emptyAction2,
  };

  /**
   * 设置 actions
   */
  setActions(actions: any) {
    this.actions = actions;
  }
  getActions() {
    return this.actions;
  }
  initActions() {
    // 模块二 主微应用通信
    let state: Record<string, any> = {
      baiduinit: "window",
      abc: 456,
      yyy: 333,
    };
    console.log(state);
    const actions: MicroAppStateActions = initGlobalState(state);
    this.actions = actions;
  }

  /**
   * 映射
   */
  onGlobalStateChange(a: any, b?: boolean) {
    return this.actions.onGlobalStateChange(a, b);
  }

  /**
   * 映射
   */
  setGlobalState(state: Record<string, any>) {
    return this.actions.setGlobalState(state);
  }
}

const actions = new Actions();
export default actions;
